package com.central.utils

import java.text.SimpleDateFormat
import java.util.{Calendar, Date}

object ParseTime {
  val sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
  val sdf_day = new SimpleDateFormat("yyyy-MM-dd")

  def DateToLong(string: String): java.lang.Long = {
    if (string.length > 13) {
      val sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
      val parse = sdf.parse(string)
      parse.getTime
    }
    else {
      string.toLong
    }
  }

  def LongToDate(string: String): String = {
    val longTime = java.lang.Long.parseLong(string)
    val date = new Date(longTime)
    return sdf.format(date)
  }

  def main(args: Array[String]): Unit = {
val string = System.currentTimeMillis().toString
    println(ParseTime.LongToDate(string))
    val date = new Date()
    println(date)
  }
}
